#include<stdio.h>
int N;		
int queenPos[100];	
void Nqueen(int k)
{
	int i;
	if(k>N)	
	{
		for(i=1;i<=N;i++)	
		{
			printf("%d ",queenPos[i]);
		}
		printf("\n");
		return ;
	} 
	for(i=1;i<=N;i++)	
	{
		int j;
		for(j=1;j<k;j++)	
		{
			if(i==queenPos[j]||i-queenPos[j]==k-j||i-queenPos[j]==j-k)
				break;
		}
		if(j==k)	
		{
			queenPos[k]=i;
			Nqueen(k+1);	
		}
	}
}
int main()
{
	scanf("%d",&N); 
	Nqueen(1);	
	return 0;
}
